package com.zzl.bonds.ticket.controller;

import com.zzl.apidoc.annotation.ApidocController;
import com.zzl.apidoc.annotation.ApidocOperation;
import com.zzl.apidoc.annotation.ApidocParam;
import com.zzl.bonds.ticket.dto.TicketFlowChartDto;
import com.zzl.bonds.ticket.service.TicketFlowChartService;
import com.zzl.general.common.apidoc.annotation.ApidocResultKeyValR;
import com.zzl.general.common.apidoc.annotation.ApidocReturnR;
import com.zzl.general.common.apidoc.constants.ResultTypeInR;
import com.zzl.general.common.ctrl.WebBaseCtrl;
import com.zzl.general.common.exception.SysException;
import com.zzl.general.common.utils.Result;
import com.zzl.general.common.utils.Tools;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 流程图表
 *
 * @author sunpp
 * @date 2022-02-16 11:14:07
 */
@ApidocController("8流程图表")
@RestController
@SuppressWarnings("javadoc")
@RequestMapping("bondsticket/tickeflowchart")
@Slf4j
public class TickeflowChartController extends WebBaseCtrl {
    @SuppressWarnings("all")
    @Autowired
    private TicketFlowChartService ticketFlowChartService;

    /**
     * 转让申请详情票据流转图
     */
    @GetMapping("/transfer/{transferId}")
    @ApidocOperation(description = "转让申请详情票据流转图", operationId = "ticket/ticket/pageMyNegotiableInstrument")
    @ApidocReturnR(otherkv = {
            @ApidocResultKeyValR(resultType = ResultTypeInR.TYPE_OBJECT, key = "data", valueClass = TicketFlowChartDto.class)
    })
    public Result transferFlowChart(@ApidocParam(name = "转让申请id", required = true) @PathVariable String transferId) {
        if (Tools.isEmpty(transferId)) {
            return Result.error("未传参数！");
        }
        try {
            return Result.ok().data(ticketFlowChartService.transferFlowChart(transferId));
        } catch (SysException e) {
            return Result.error(e.getMsg());
        }
    }

    @GetMapping("/getFlowchart/{financeId}")
    @ApidocOperation(description = "融资申请详情票据流转图", operationId = "ticket/ticket/getFlowchart")
    @ApidocReturnR(otherkv = {
            @ApidocResultKeyValR(resultType = ResultTypeInR.TYPE_OBJECT, key = "data", valueClass = TicketFlowChartDto.class)
    })
    public Result getFlowchart(@ApidocParam(name = "financeId", description = "融资申请id", required = true) @PathVariable String financeId) {
        try {
            return Result.ok().data(ticketFlowChartService.transferFlowChart(financeId));
        } catch (SysException e) {
            return Result.error(e.getMsg());
        }
    }

    /**
     * 我的票据详情票据流转图
     */
    @GetMapping("/ticket/{ticketId}")
    @ApidocOperation(description = "我的票据详情票据流转图", operationId = "ticket/ticket/pageMyNegotiableInstrument")
    @ApidocReturnR(otherkv = {
            @ApidocResultKeyValR(resultType = ResultTypeInR.TYPE_OBJECT, key = "data", valueClass = TicketFlowChartDto.class)
    })
    public Result ticketFlowChart(@ApidocParam(name = "票据id", required = true) @PathVariable String ticketId) {
        if (Tools.isEmpty(ticketId)) {
            return Result.error("未传参数！");
        }
        try {
            return Result.ok().data(ticketFlowChartService.ticketFlowChart(ticketId));
        } catch (SysException e) {
            return Result.error(e.getMsg());
        }
    }

    /**
     * 开立签收详情票据流转图
     */
    @GetMapping("/openSign/{ticketOpenId}")
    @ApidocOperation(description = "开立签收详情票据流转图", operationId = "ticket/ticket/pageMyNegotiableInstrument")
    @ApidocReturnR(otherkv = {
            @ApidocResultKeyValR(resultType = ResultTypeInR.TYPE_OBJECT, key = "data", valueClass = TicketFlowChartDto.class)
    })
    public Result openSign(@ApidocParam(name = "票据id", required = true) @PathVariable String ticketOpenId) {
        if (Tools.isEmpty(ticketOpenId)) {
            return Result.error("未传参数！");
        }
        try {
            return Result.ok().data(ticketFlowChartService.openSign(ticketOpenId));
        } catch (SysException e) {
            return Result.error(e.getMsg());
        }
    }


    /**
     * 开立详情票据流转总图
     */
    @GetMapping("/openSignAll/{ticketOpenId}")
    @ApidocOperation(description = "开立详情票据流转总图", operationId = "ticket/ticket/pageMyNegotiableInstrument/11")
    @ApidocReturnR(otherkv = {
            @ApidocResultKeyValR(resultType = ResultTypeInR.TYPE_OBJECT, key = "data", valueClass = TicketFlowChartDto.class)
    })
    public Result openSignAll(@ApidocParam(name = "票据id", required = true) @PathVariable String ticketOpenId) {
        if (Tools.isEmpty(ticketOpenId)) {
            return Result.error("未传参数！");
        }
        try {
            return Result.ok().data(ticketFlowChartService.openSignAll(ticketOpenId));
        } catch (SysException e) {
            return Result.error(e.getMsg());
        }
    }
}
